using System;
using System.Collections.Generic;
using System.Xml;
using System.Collections.ObjectModel;

namespace planning
{
	public class Semaine : ObservableObject
	{
		// ----- ATTRIBUTS -----
		private int numero;
		private ICollection<Jour> jours = new ObservableCollection<Jour>();

		// ----- CONSTRUCTEURS -----
		public Semaine()
		{
			// Start of user code for default constructor
			// End of user code for default constructor
		}

		// ----- ACCESSEURS -----
		public int Numero
		{
			get { return numero; }
			set { numero = value; ObjectChanged("numero"); }
		}

		public ICollection<Jour> Jours
		{
			get { return jours; }
			set { jours = value; ObjectChanged("jours"); }
		}


		static Dictionary<string, Semaine> references = new Dictionary<string, Semaine>();

		public static Semaine fromXml(XmlNode node)
		{
			if(node.SelectSingleNode("@ref") != null)
				return references[node.SelectSingleNode("@ref").Value];

			Semaine semaine = new Semaine();

			if(node.SelectSingleNode("@id") != null) {
				references.Add(node.SelectSingleNode("@id").Value, semaine);
			}

			semaine.Numero = Convert.ToInt32(node.SelectSingleNode("@numero").Value);
			foreach (XmlNode subElement in node.SelectNodes("jours/*"))
			{
				Jour subObject = Jour.fromXml(subElement);
				semaine.jours.Add(subObject);
			}

			

			return semaine;

		}

	}

}
